package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhangtai.modules.dto.CredentialHangDto;
import com.zhangtai.modules.dto.CredentialInfoDto;
import com.zhangtai.modules.entity.credential.CredentialHangEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-10-15 15:22:38
 */
@Mapper
public interface CredentialHangDao extends BaseMapper<CredentialHangEntity> {

    @Select("<script>select t1.oid,t1.credential_no,t1.manger_no,t1.start_time,t1.end_time,t1.credential_level," +
            "t1.job_series,t1.credential_name,t1.profession,t1.approval_authority,t1.register_org,t1.file_url,t1.is_audit,t1.hang_status," +
            "t3.id,t3.reason,t3.allowance,t3.allowance_time,t3.file_url refuse_url,t3.bpm_url," +
            "t2.name,t2.idcard,t2.gender,t2.birthday,t3.status audit from tb_credential_hang t3 left join  tb_credential_info t1 on t3.credential_id = t1.id " +
            "left join tb_employee_info t2 on t1.oid = t2.oid " +
            "<where>  t3.is_delete = 0 " +
            "<if test='name!=null and name!=&apos;&apos;'>and name like '%${name}%' </if>" +
            "<if test='status!=null and status.size>0'> and t3.status in " +
            " <foreach item=\"s\" index=\"index\" collection=\"status\" open=\"(\" separator=\",\" close=\")\">#{s}</foreach>" +
            "</if>"+
            "<if test='orgIds!=null and orgIds.size>0'> and t1.unit_id in " +
            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
            "</if>"+
            "<if test='orgIds==null or orgIds.size==0'> and t1.unit_id = null " +

            "</if>"+
            "</where>" +
            "order by t3.create_time desc </script>")
    List<CredentialHangDto> geHangInfoList(@Param("name") String name,
                                                  @Param("status") List<Integer> status,
                                                  @Param("orgIds") List<Long> orgIds,
                                                  IPage<CredentialHangDto> page);

    @Update("update tb_credential_hang set status = 4 where credential_id = #{credentialId} and status = 2")
    void unVaildHang(@Param("credentialId") Long credentialId);
}
